package com.yss.ams.demo.controller;

import com.yss.ams.demo.config.DBContextHolder;
import com.yss.ams.demo.pojo.User;
import com.yss.ams.demo.service.DBChangeService;
import com.yss.ams.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shenyao
 * @date 2021/3/28
 * @description:
 */

@RestController
public class TestController {
    @Autowired
    private DBChangeService dbChangeServiceImpl;
    @Autowired
    UserService userService;




    /**
     * 查询所有
     * @return
     */
    @GetMapping("/test")
    public  String test() throws Exception {


        String datasourceId="game_message";
        dbChangeServiceImpl.changeDb(datasourceId);
        List<User> userList= userService.queryUserInfo();
        System.out.println(userList.toString());


        dbChangeServiceImpl.changeDb("game_message_cluster");
        List<User> userList3= userService.queryUserInfo();
        System.out.println(userList3.toString());


        //切回主数据源
        DBContextHolder.clearDataSource();
        return "ok";
    }

}
